﻿/**
 * Copyright (C), 2004-2006, 三五互联科技有限公司
 * File Name: 获取设置cookie.js
 * Encoding UTF-8
 * Version: 1.0
 * Date: Nov 1, 2006
 * History:	
 * @author:杨先亭(nathena) yangxt@china-channel.com
 * @version:Revision: 1.00 Date: Nov 1, 2006
 */
 
/**
 * cookie-获取cookie 
 * @param varName,所要获取的cookie名字
 */ 
function getCookie(varName)
{
	var srcCookie=window.document.cookie;
	if(srcCookie=="")
	{
		return "";
	}
	var nPos=srcCookie.lastIndexOf(varName+"=");
	if(nPos>0)
	{	
		if(nPos>=2)
		{
			nPos=srcCookie.indexOf("; "+varName+"=",nPos-2);
		}
		else
		{
			nPos=srcCookie.indexOf("; "+varName+"=");
		}
	}
	if(nPos>=0)
	{	
		nPos=srcCookie.indexOf('=',nPos)+1;
		var nTailPos=srcCookie.indexOf("; ",nPos);
		if(nTailPos>0)
		{
			return srcCookie.substring(nPos,nTailPos);
		}
		else
		{
			return srcCookie.substr(nPos);
		}
	}
	return "";
};//~end

/**
 * cookie-设置cookie 
 * @param varName,所要设置的cookie名字
 */ 
function setCookie(sName,sValue,date)
{
	var sCookie="";
	/**
	 * 过期
	 */
	var date=date||new Date(2099,12,31).toGMTString();
	sCookie=sName+'='+escape(sValue)+";expires=" + date+";path=/;domain="+document.domain;
	window.document.cookie=sCookie ;
};//~end